package com.tledu.zyf.servlet.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tledu.zyf.model.User;
import com.tledu.zyf.service.IUserService;
import com.tledu.zyf.util.ForwardUtil;
import com.tledu.zyf.util.ObjectFactory;

@WebServlet("/user/list")
public class UserListServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取 UserService 对象
		IUserService userService = ObjectFactory.getUserService();
		// 调用 list 方法 , 获取所有的用户数据
		List<User> users = userService.list();
		// 传递到页面
		request.setAttribute("users", users);
		// 跳转到对应的展示页面
//		request.getRequestDispatcher("/WEB-INF/jsp/user/list.jsp").forward(request, response);
		ForwardUtil.forward(request, response, "user/list");
	}
}
